package cn.valo.system.controller;

import cn.valo.system.domain.SystemDictionaryDetail;
import cn.valo.system.query.SystemDictionaryDetailQuery;
import cn.valo.system.service.ISystemDictionaryDetailService;
import cn.valo.basic.util.AjaxResult;
import cn.valo.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdd")
public class SystemDictionaryDetailController {
    @Autowired
    private ISystemDictionaryDetailService iSystemDictionaryDetailService;
    //id查询
    @GetMapping("/{id}")
    public SystemDictionaryDetail queryById(@PathVariable("id") Long id){
        return iSystemDictionaryDetailService.queryById(id);
    }
    //查所有
    @GetMapping()
    public List<SystemDictionaryDetail> queryAll(){
        return iSystemDictionaryDetailService.queryAll();
    }
    //高级查询+分页
    @PostMapping
    public PageList<SystemDictionaryDetail> list(@RequestBody SystemDictionaryDetailQuery query){
        System.out.println("-------------");
        System.out.println(query);
        return iSystemDictionaryDetailService.queryPage(query);
    }
    //高级查询+分页d
    @PostMapping("/d")
    public PageList<SystemDictionaryDetail> listd(@RequestBody SystemDictionaryDetailQuery query){
        System.out.println("-------------");
        System.out.println(query);
        return iSystemDictionaryDetailService.queryPageByTpypeid(query);
    }


    @DeleteMapping("/{id}") // /systemDictionaryDetail/1
    public AjaxResult delete(@PathVariable("id") Long id) {
        try {
            iSystemDictionaryDetailService.removeById(id);

            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
    @PutMapping //添加或修改
    public AjaxResult addOrUpdate(@RequestBody SystemDictionaryDetail systemDictionaryDetail) {
        System.out.println(systemDictionaryDetail);
        try {
            if (systemDictionaryDetail.getId() != null) {
                iSystemDictionaryDetailService.update(systemDictionaryDetail);
            } else {
                iSystemDictionaryDetailService.save(systemDictionaryDetail);
            }

            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }

    }
    //批量删除
    @PatchMapping
    public AjaxResult delete(@RequestBody List<Long> ids) {
        try {
            iSystemDictionaryDetailService.remove(ids);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
}
